using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VSTDLZ
    {
        public DataRow Convert2STDLZ(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QuerySTDLZ(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["SDZMANDANT"] = " ".PadRight(2 ); 
         dwReturn["SDZSTUFE"] = " ".PadRight(1 ); 
         dwReturn["SDZSAKSTKRS"] = " ".PadRight(2 ); 
         dwReturn["SDZSAKST"] = " ".PadRight(4 ); 
         dwReturn["SDZMONAT"] = " ".PadRight(6 ); 
         dwReturn["SDZPROGRP"] = " ".PadRight(3 ); 
         dwReturn["SDZARTGRP"] = " ".PadRight(3 ); 
         dwReturn["SDZGANZPRT"] = " ".PadRight(0 ); 
         dwReturn["SDZGBRBSTD"] = " ".PadRight(0 ); 
         dwReturn["SDZGDLAUFZ"] = " ".PadRight(0 ); 
         dwReturn["SDZIANZAUF1"] = " ".PadRight(0 ); 
         dwReturn["SDZIANZAUF2"] = " ".PadRight(0 ); 
         dwReturn["SDZIANZAUF3"] = " ".PadRight(0 ); 
         dwReturn["SDZIANZAUF4"] = " ".PadRight(0 ); 
         dwReturn["SDZIANZAUF5"] = " ".PadRight(0 ); 
         dwReturn["SDZIANZAUF6"] = " ".PadRight(0 ); 
         dwReturn["SDZDANZAUF1"] = " ".PadRight(0 ); 
         dwReturn["SDZDANZAUF2"] = " ".PadRight(0 ); 
         dwReturn["SDZDANZAUF3"] = " ".PadRight(0 ); 
         dwReturn["SDZDANZAUF4"] = " ".PadRight(0 ); 
         dwReturn["SDZDANZAUF5"] = " ".PadRight(0 ); 
         dwReturn["SDZDANZAUF6"] = " ".PadRight(0 ); 
         dwReturn["SDZVANZAUF1"] = " ".PadRight(0 ); 
         dwReturn["SDZVANZAUF2"] = " ".PadRight(0 ); 
         dwReturn["SDZVANZAUF3"] = " ".PadRight(0 ); 
         dwReturn["SDZVANZAUF4"] = " ".PadRight(0 ); 
         dwReturn["SDZVANZAUF5"] = " ".PadRight(0 ); 
         dwReturn["SDZVANZAUF6"] = " ".PadRight(0 ); 
         dwReturn["SDZBANZAUF1"] = " ".PadRight(0 ); 
         dwReturn["SDZBANZAUF2"] = " ".PadRight(0 ); 
         dwReturn["SDZBANZAUF3"] = " ".PadRight(0 ); 
         dwReturn["SDZBANZAUF4"] = " ".PadRight(0 ); 
         dwReturn["SDZBANZAUF5"] = " ".PadRight(0 ); 
         dwReturn["SDZBANZAUF6"] = " ".PadRight(0 ); 
         dwReturn["SDZFILLER"] = " ".PadRight(71 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapSTDLZ(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveSTDLZ(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QuerySTDLZ(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapSTDLZ(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertSTDLZ(dwLocal, ITXDBVERSION);
            }
            UpdateSTDLZ(dwLocal);
        }
        public void InsertSTDLZ(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO STDLZ(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QuerySTDLZ(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM STDLZ WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM STDLZ  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "STDLZ";
            Return = Result;
            return Return;
        }
        public void DeleteSTDLZ(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM STDLZ   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateSTDLZ(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE STDLZ SET "
                    +"SDZMANDANT= :SDZMANDANT,"
                    +"SDZSTUFE= :SDZSTUFE,"
                    +"SDZSAKSTKRS= :SDZSAKSTKRS,"
                    +"SDZSAKST= :SDZSAKST,"
                    +"SDZMONAT= :SDZMONAT,"
                    +"SDZPROGRP= :SDZPROGRP,"
                    +"SDZARTGRP= :SDZARTGRP,"
                    +"SDZGANZPRT= :SDZGANZPRT,"
                    +"SDZGBRBSTD= :SDZGBRBSTD,"
                    +"SDZGDLAUFZ= :SDZGDLAUFZ,"
                    +"SDZIANZAUF1= :SDZIANZAUF1,"
                    +"SDZIANZAUF2= :SDZIANZAUF2,"
                    +"SDZIANZAUF3= :SDZIANZAUF3,"
                    +"SDZIANZAUF4= :SDZIANZAUF4,"
                    +"SDZIANZAUF5= :SDZIANZAUF5,"
                    +"SDZIANZAUF6= :SDZIANZAUF6,"
                    +"SDZDANZAUF1= :SDZDANZAUF1,"
                    +"SDZDANZAUF2= :SDZDANZAUF2,"
                    +"SDZDANZAUF3= :SDZDANZAUF3,"
                    +"SDZDANZAUF4= :SDZDANZAUF4,"
                    +"SDZDANZAUF5= :SDZDANZAUF5,"
                    +"SDZDANZAUF6= :SDZDANZAUF6,"
                    +"SDZVANZAUF1= :SDZVANZAUF1,"
                    +"SDZVANZAUF2= :SDZVANZAUF2,"
                    +"SDZVANZAUF3= :SDZVANZAUF3,"
                    +"SDZVANZAUF4= :SDZVANZAUF4,"
                    +"SDZVANZAUF5= :SDZVANZAUF5,"
                    +"SDZVANZAUF6= :SDZVANZAUF6,"
                    +"SDZBANZAUF1= :SDZBANZAUF1,"
                    +"SDZBANZAUF2= :SDZBANZAUF2,"
                    +"SDZBANZAUF3= :SDZBANZAUF3,"
                    +"SDZBANZAUF4= :SDZBANZAUF4,"
                    +"SDZBANZAUF5= :SDZBANZAUF5,"
                    +"SDZBANZAUF6= :SDZBANZAUF6,"
                    +"SDZFILLER= :SDZFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("SDZMANDANT", OracleType.NVarChar).Value = dwData["SDZMANDANT"].ToString(); 
          or1.Parameters.Add("SDZSTUFE", OracleType.NVarChar).Value = dwData["SDZSTUFE"].ToString(); 
          or1.Parameters.Add("SDZSAKSTKRS", OracleType.NVarChar).Value = dwData["SDZSAKSTKRS"].ToString(); 
          or1.Parameters.Add("SDZSAKST", OracleType.NVarChar).Value = dwData["SDZSAKST"].ToString(); 
          or1.Parameters.Add("SDZMONAT", OracleType.NVarChar).Value = dwData["SDZMONAT"].ToString(); 
          or1.Parameters.Add("SDZPROGRP", OracleType.NVarChar).Value = dwData["SDZPROGRP"].ToString(); 
          or1.Parameters.Add("SDZARTGRP", OracleType.NVarChar).Value = dwData["SDZARTGRP"].ToString(); 
          or1.Parameters.Add("SDZGANZPRT", OracleType.NVarChar).Value = dwData["SDZGANZPRT"].ToString(); 
          or1.Parameters.Add("SDZGBRBSTD", OracleType.NVarChar).Value = dwData["SDZGBRBSTD"].ToString(); 
          or1.Parameters.Add("SDZGDLAUFZ", OracleType.NVarChar).Value = dwData["SDZGDLAUFZ"].ToString(); 
          or1.Parameters.Add("SDZIANZAUF1", OracleType.NVarChar).Value = dwData["SDZIANZAUF1"].ToString(); 
          or1.Parameters.Add("SDZIANZAUF2", OracleType.NVarChar).Value = dwData["SDZIANZAUF2"].ToString(); 
          or1.Parameters.Add("SDZIANZAUF3", OracleType.NVarChar).Value = dwData["SDZIANZAUF3"].ToString(); 
          or1.Parameters.Add("SDZIANZAUF4", OracleType.NVarChar).Value = dwData["SDZIANZAUF4"].ToString(); 
          or1.Parameters.Add("SDZIANZAUF5", OracleType.NVarChar).Value = dwData["SDZIANZAUF5"].ToString(); 
          or1.Parameters.Add("SDZIANZAUF6", OracleType.NVarChar).Value = dwData["SDZIANZAUF6"].ToString(); 
          or1.Parameters.Add("SDZDANZAUF1", OracleType.NVarChar).Value = dwData["SDZDANZAUF1"].ToString(); 
          or1.Parameters.Add("SDZDANZAUF2", OracleType.NVarChar).Value = dwData["SDZDANZAUF2"].ToString(); 
          or1.Parameters.Add("SDZDANZAUF3", OracleType.NVarChar).Value = dwData["SDZDANZAUF3"].ToString(); 
          or1.Parameters.Add("SDZDANZAUF4", OracleType.NVarChar).Value = dwData["SDZDANZAUF4"].ToString(); 
          or1.Parameters.Add("SDZDANZAUF5", OracleType.NVarChar).Value = dwData["SDZDANZAUF5"].ToString(); 
          or1.Parameters.Add("SDZDANZAUF6", OracleType.NVarChar).Value = dwData["SDZDANZAUF6"].ToString(); 
          or1.Parameters.Add("SDZVANZAUF1", OracleType.NVarChar).Value = dwData["SDZVANZAUF1"].ToString(); 
          or1.Parameters.Add("SDZVANZAUF2", OracleType.NVarChar).Value = dwData["SDZVANZAUF2"].ToString(); 
          or1.Parameters.Add("SDZVANZAUF3", OracleType.NVarChar).Value = dwData["SDZVANZAUF3"].ToString(); 
          or1.Parameters.Add("SDZVANZAUF4", OracleType.NVarChar).Value = dwData["SDZVANZAUF4"].ToString(); 
          or1.Parameters.Add("SDZVANZAUF5", OracleType.NVarChar).Value = dwData["SDZVANZAUF5"].ToString(); 
          or1.Parameters.Add("SDZVANZAUF6", OracleType.NVarChar).Value = dwData["SDZVANZAUF6"].ToString(); 
          or1.Parameters.Add("SDZBANZAUF1", OracleType.NVarChar).Value = dwData["SDZBANZAUF1"].ToString(); 
          or1.Parameters.Add("SDZBANZAUF2", OracleType.NVarChar).Value = dwData["SDZBANZAUF2"].ToString(); 
          or1.Parameters.Add("SDZBANZAUF3", OracleType.NVarChar).Value = dwData["SDZBANZAUF3"].ToString(); 
          or1.Parameters.Add("SDZBANZAUF4", OracleType.NVarChar).Value = dwData["SDZBANZAUF4"].ToString(); 
          or1.Parameters.Add("SDZBANZAUF5", OracleType.NVarChar).Value = dwData["SDZBANZAUF5"].ToString(); 
          or1.Parameters.Add("SDZBANZAUF6", OracleType.NVarChar).Value = dwData["SDZBANZAUF6"].ToString(); 
          or1.Parameters.Add("SDZFILLER", OracleType.NVarChar).Value = dwData["SDZFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
